package com.tom.dataLoader;

import java.util.HashMap;
import java.util.Map;

import com.tom.SampleDataLocalCacheWrapper;
import com.tom.dataLoader.LocalCacheDataLoader.RemoteCacheDataTicket;


public class RemoteCacheDataLoader{
	//mock Tair
	Map<Integer,SampleDataLocalCacheWrapper> mockCache = new HashMap<Integer,SampleDataLocalCacheWrapper>();
	//mock Tair
	Map<Integer,RemoteCacheDataTicket> mockCache_ticket = new HashMap<Integer,RemoteCacheDataTicket>();
	
	DBDataLoader dbDataLoader = new DBDataLoader();
	
	public SampleDataLocalCacheWrapper get(Integer key) {
		SampleDataLocalCacheWrapper dataWrapper = mockCache.get(key);
		if(dataWrapper == null){
			dataWrapper = new SampleDataLocalCacheWrapper(dbDataLoader.get(key));
			mockCache.put(key, dataWrapper);
			mockCache_ticket.put(key, new RemoteCacheDataTicket(key));
			return dataWrapper;
		}
		return dataWrapper;
	}
	
	public RemoteCacheDataTicket getTicket(Integer key) {
		return mockCache_ticket.get(key);
	}
	
	public void put(Integer key,SampleDataLocalCacheWrapper dataWrapper) {
		mockCache.put(key, dataWrapper);
	}
	
	public void putTicket(Integer key,RemoteCacheDataTicket ticket) {
		mockCache_ticket.put(key, ticket);
	}

}
